<!DOCTYPE html>
<html  lang="zh-CN" >
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="theme-color" content="#fff" id="theme-color">
  <meta name="description" content="深山磨柴斧，一鸣震江湖">
  <link rel="icon" href="/img/ic_head.jpg">
  <title>016-Android自定义View(11)：手势监听处理实践之双指缩放双击复原ImageView</title>
  
  
  <meta property="og:title" content="016-Android自定义View(11)：手势监听处理实践之双指缩放双击复原ImageView">
  
  
  <meta property="og:url" content="http://example.com/2019/07/27/016-Android%E8%87%AA%E5%AE%9A%E4%B9%89View(11)%EF%BC%9A%E6%89%8B%E5%8A%BF%E7%9B%91%E5%90%AC%E5%A4%84%E7%90%86%E5%AE%9E%E8%B7%B5%E4%B9%8B%E5%8F%8C%E6%8C%87%E7%BC%A9%E6%94%BE%E5%8F%8C%E5%87%BB%E5%A4%8D%E5%8E%9FImageView/index.html">
  
  
  <meta property="og:img" content="/img/ic_head.jpg">
  
  
  <meta property="og:img" content="深山磨柴斧，一鸣震江湖">
  
  
  <meta property="og:type" content="article">
  <meta property="og:article:published_time" content="2019-07-27">
  <meta property="og:article:modified_time" content="2021-04-14">
  <meta property="og:article:author" content="Cupster">
  
  
  <meta property="og:article:tag" content="Android">
  
  <meta property="og:article:tag" content="Android自定义View">
  
  <meta property="og:article:tag" content="Android事件">
  
  <meta property="og:article:tag" content="Android手势">
  
  
  
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
    var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
      }
    };
    setDarkmode();
  </script>
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
  </script>
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
  <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
  
  
  
  
<link rel="stylesheet" href="/css/main.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">

  
  
<link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">

  
  
  
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <div class="wrapper">
    
    <nav class="navbar">
  <div class="navbar-logo">
    <span class="navbar-logo-main">
      
      <img class="navbar-logo-img" src="/img/ic_head.jpg" alt="logo">
      
      <span class="navbar-logo-dsc">不负明天</span>
    </span>
  </div>
  <div class="navbar-menu">
    
    <a href="/" class="navbar-menu-item">
    
    首页
    
    </a>
    
    <a href="/archives" class="navbar-menu-item">
    
    归档
    
    </a>
    
    <a href="/tags" class="navbar-menu-item">
    
    标签
    
    </a>
    
    <a href="/categories" class="navbar-menu-item">
    
    分类
    
    </a>
    
    <a href="/about" class="navbar-menu-item">
    
    关于
    
    </a>
    
    <a href="/links" class="navbar-menu-item">
    
    友链
    
    </a>
    
    <a class="navbar-menu-item darknavbar" id="dark"><i class="iconfont icon-weather"></i></a>
    <a class="navbar-menu-item searchnavbar" id="search"><i class="iconfont icon-search" style="font-size: 1.2rem; font-weight: 400;"></i></a>
  </div>
</nav>
    
    <div id="local-search" style="display: none;">
      <input class="navbar-menu-item" id="search-input" placeholder="请输入搜索内容...">
      <div id="search-content"></div>
    </div>
    
    <div class="section-wrap">
      <div class="container">
        <div class="columns">
          <main class="main-column">
<article class="card card-content">
  <header>
    <h1 class="post-title">
      016-Android自定义View(11)：手势监听处理实践之双指缩放双击复原ImageView
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2019-07-27T04:20:37.000Z">
      <i class="iconfont icon-calendar" style="margin-right: 2px;"></i>
      <span>2019-07-27</span>
    </time>
    
    <span class="dot"></span>
    
    <a href="/categories/Android/" class="post-meta-link">Android</a>
    
    
    
    <span class="dot"></span>
    <span>1.1k 字</span>
    
  </div>
  
  <div class="post-meta post-show-meta" style="margin-top: -10px;">
    <div style="display: flex; align-items: center;">
      <i class="iconfont icon-biaoqian" style="margin-right: 2px; font-size: 1.15rem;"></i>
      
      
        <a href="/tags/Android/" class="post-meta-link">Android</a>
      
      
      <span class="dot"></span>
      
        <a href="/tags/Android自定义View/" class="post-meta-link">Android自定义View</a>
      
      
      <span class="dot"></span>
      
        <a href="/tags/Android事件/" class="post-meta-link">Android事件</a>
      
      
      <span class="dot"></span>
      
        <a href="/tags/Android手势/" class="post-meta-link">Android手势</a>
      
    </div>
  </div>
  
  </header>
  <div id="section" class="post-content">
    <p> <a target="_blank" rel="noopener" href="https://blog.csdn.net/Cupster/article/details/112988311">【5年Android从零复盘系列之十六】Android自定义View(11)：手势监听处理实践之双指缩放双击复原可拖拽ImageView</a></p>
<hr />

<h1 id="1-效果"><a href="#1-效果" class="headerlink" title="1.效果"></a>1.效果</h1><p>1.拖拽</p>
<img src="https:/ srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://gitee.com/cupster/picbed/raw/master/uPic/20210122160838_拖动.gif" class="lozad post-image"/gitee.com/cupster/picbed/raw/master/uPic/20210122160838_拖动.gif"/>

<p>2.双击复原、双指缩放</p>
<img src="https:/ srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://gitee.com/cupster/picbed/raw/master/uPic/20210122163135_缩放的.gif" class="lozad post-image"/gitee.com/cupster/picbed/raw/master/uPic/20210122163135_缩放的.gif"/>

<p>3.点击回调、关闭activity</p>
<img src="https://gitee.com/cupster/picbed/raw/master/uPic/20210122161825_单击返回.gif" / srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://gitee.com/cupster/picbed/raw/master/uPic/20210122161825_单击返回.gif" class="lozad post-image">

<h1 id="2-监听手势实现功能"><a href="#2-监听手势实现功能" class="headerlink" title="2.监听手势实现功能"></a>2.监听手势实现功能</h1><ol>
<li>双指缩放</li>
<li>拖拽移动</li>
<li>点击事件回调（查看大图的Activity中可以finish）</li>
<li>双击事件回调，图片复原</li>
</ol>
<h1 id="3-用法及代码详解"><a href="#3-用法及代码详解" class="headerlink" title="3.用法及代码详解"></a>3.用法及代码详解</h1><h2 id="3-1属性添加"><a href="#3-1属性添加" class="headerlink" title="3.1属性添加"></a>3.1属性添加</h2><p>/res/value/attrs.xml添加属性节点</p>
<pre class="highlight"><span class="line"><span class="tag">&lt;<span class="name">declare-styleable</span> <span class="attr">name</span>=<span class="string">&quot;ScaleImageView&quot;</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;img_src&quot;</span> <span class="attr">format</span>=<span class="string">&quot;reference&quot;</span> /&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">declare-styleable</span>&gt;</span></span><br></pre>

<h2 id="3-2xml布局文件中使用"><a href="#3-2xml布局文件中使用" class="headerlink" title="3.2xml布局文件中使用"></a>3.2xml布局文件中使用</h2><p>留意使用自定义属性</p>
<pre class="highlight"><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">RelativeLayout</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:app</span>=<span class="string">&quot;http://schemas.android.com/apk/res-auto&quot;</span>&gt;</span></span><br><span class="line">        &lt;com.cupster.base_super_resource.gesturedetector.ScaleImageView</span><br><span class="line">            android:id=&quot;@+id/tv_words&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:minHeight=&quot;120dp&quot;</span><br><span class="line">            android:minWidth=&quot;120dp&quot;</span><br><span class="line">            app:img_src=&quot;@mipmap/pic_drinking&quot;</span><br><span class="line">            android:layout_centerInParent=&quot;true&quot;</span><br><span class="line">            /&gt;</span><br><span class="line"><span class="tag">&lt;/<span class="name">RelativeLayout</span>&gt;</span></span><br></pre>

<h2 id="3-3Activity使用"><a href="#3-3Activity使用" class="headerlink" title="3.3Activity使用"></a>3.3Activity使用</h2><pre class="highlight"><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ScaleGesTureActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> <span class="keyword">implements</span> <span class="title">ScaleImageView</span>.<span class="title">OperateListener</span></span>&#123;</span><br><span class="line">     ScaleImageView mTvGesture;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(<span class="meta">@Nullable</span> Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_gesture_detector);</span><br><span class="line">        mTvGesture = findViewById(R.id.tv_words);</span><br><span class="line">        mTvGesture.setOperateListener( <span class="keyword">this</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClicked</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        finish();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onDoubleClicked</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre>

<h2 id="3-4ScaleImageView详解"><a href="#3-4ScaleImageView详解" class="headerlink" title="3.4ScaleImageView详解"></a>3.4ScaleImageView详解</h2><pre class="highlight"><span class="line"><span class="keyword">package</span> com.cupster.base_super_resource.gesturedetector;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.content.Context;</span><br><span class="line"><span class="keyword">import</span> android.content.res.TypedArray;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Bitmap;</span><br><span class="line"><span class="keyword">import</span> android.graphics.BitmapFactory;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Canvas;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Matrix;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Paint;</span><br><span class="line"><span class="keyword">import</span> android.graphics.PointF;</span><br><span class="line"><span class="keyword">import</span> android.graphics.RectF;</span><br><span class="line"><span class="keyword">import</span> android.util.AttributeSet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.view.GestureDetector;</span><br><span class="line"><span class="keyword">import</span> android.view.MotionEvent;</span><br><span class="line"><span class="keyword">import</span> android.view.ScaleGestureDetector;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.widget.ImageView;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.cupster.base_super_resource.R;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ScaleImageView</span> <span class="keyword">extends</span> <span class="title">ImageView</span> <span class="keyword">implements</span> <span class="title">ScaleGestureDetector</span>.<span class="title">OnScaleGestureListener</span>,  <span class="title">GestureDetector</span>.<span class="title">OnDoubleTapListener</span>,<span class="title">GestureDetector</span>.<span class="title">OnGestureListener</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> ScaleGestureDetector scaleGestureDetector;</span><br><span class="line">    <span class="keyword">private</span> GestureDetector gestureDetector;</span><br><span class="line"></span><br><span class="line">    Bitmap mBitmap;         <span class="comment">// 图片</span></span><br><span class="line">    RectF mBitmapRectF;     <span class="comment">// 图片所在区域</span></span><br><span class="line">    Matrix mBitmapMatrix;   <span class="comment">// 控制图片的 matrix</span></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 图片宽度</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> mBitmapWidth;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 图片高度</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> mBitmapHeight;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 控件宽度</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> mWidth;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 控件高度</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> mHeight;</span><br><span class="line">    <span class="keyword">boolean</span> canDrag = <span class="keyword">false</span>;</span><br><span class="line">    PointF lastPoint = <span class="keyword">new</span> PointF(<span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">ScaleImageView</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>(context, <span class="keyword">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">ScaleImageView</span><span class="params">(Context context, AttributeSet attrs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs);</span><br><span class="line"></span><br><span class="line">        BitmapFactory.Options options = <span class="keyword">new</span> BitmapFactory.Options();</span><br><span class="line">        options.outWidth = <span class="number">960</span>/<span class="number">2</span>;</span><br><span class="line">        options.outHeight = <span class="number">800</span>/<span class="number">2</span>;</span><br><span class="line"></span><br><span class="line">        mDeafultPaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        TypedArray typedArray = context.obtainStyledAttributes(attrs ,R.styleable.ScaleImageView);</span><br><span class="line">        <span class="keyword">int</span> resId = typedArray.getResourceId(R.styleable.ScaleImageView_img_src , R.mipmap.ic_launcher);</span><br><span class="line">        typedArray.recycle();</span><br><span class="line">        mBitmap = BitmapFactory.decodeResource(<span class="keyword">this</span>.getResources(), resId, options);</span><br><span class="line">        mBitmapWidth = mBitmap.getWidth();</span><br><span class="line">        mBitmapHeight = mBitmap.getHeight();</span><br><span class="line">        mBitmapRectF = <span class="keyword">new</span> RectF(<span class="number">0</span>,<span class="number">0</span>,mBitmap.getWidth(), mBitmap.getHeight());</span><br><span class="line">        mBitmapMatrix = <span class="keyword">new</span> Matrix();</span><br><span class="line"></span><br><span class="line">        scaleGestureDetector = <span class="keyword">new</span> ScaleGestureDetector(context, <span class="keyword">this</span>);</span><br><span class="line">        gestureDetector = <span class="keyword">new</span> GestureDetector(context ,<span class="keyword">this</span>);</span><br><span class="line">        gestureDetector.setIsLongpressEnabled(<span class="keyword">true</span>);</span><br><span class="line">        gestureDetector.setOnDoubleTapListener(<span class="keyword">this</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onMeasure</span><span class="params">(<span class="keyword">int</span> widthMeasureSpec, <span class="keyword">int</span> heightMeasureSpec)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onMeasure(widthMeasureSpec, heightMeasureSpec);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onLayout</span><span class="params">(<span class="keyword">boolean</span> changed, <span class="keyword">int</span> left, <span class="keyword">int</span> top, <span class="keyword">int</span> right, <span class="keyword">int</span> bottom)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onLayout(changed, left, top, right, bottom);</span><br><span class="line"></span><br><span class="line">        mWidth = getWidth();</span><br><span class="line">        mHeight = getHeight();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onTouchEvent</span><span class="params">(MotionEvent event)</span> </span>&#123;</span><br><span class="line">        gestureDetector.onTouchEvent(event);</span><br><span class="line">        scaleGestureDetector.onTouchEvent(event);</span><br><span class="line">        <span class="keyword">switch</span> (event.getActionMasked()) &#123;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_DOWN:</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_POINTER_DOWN:</span><br><span class="line">                <span class="comment">// 是否第一个手指 &amp;&amp; 点是否在图片内</span></span><br><span class="line">                <span class="keyword">if</span> (event.getPointerId(event.getActionIndex()) == <span class="number">0</span> &amp;&amp; mBitmapRectF.contains((<span class="keyword">int</span>)event.getX(), (<span class="keyword">int</span>)event.getY()))&#123;</span><br><span class="line">                    canDrag = <span class="keyword">true</span>;</span><br><span class="line">                    lastPoint.set(event.getX(), event.getY());</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_UP:</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_POINTER_UP:</span><br><span class="line">                <span class="comment">// 是否第一个手指</span></span><br><span class="line">                <span class="keyword">if</span> (event.getPointerId(event.getActionIndex()) == <span class="number">0</span>)&#123;</span><br><span class="line">                    canDrag = <span class="keyword">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_MOVE:</span><br><span class="line">                <span class="comment">// 如果存在第一个手指，且这个手指点在图片内，则拖动绘制</span></span><br><span class="line">                <span class="keyword">if</span> (canDrag) &#123;</span><br><span class="line">                    <span class="keyword">int</span> index = event.findPointerIndex(<span class="number">0</span>);</span><br><span class="line">                    mBitmapMatrix.postTranslate(event.getX(index)-lastPoint.x, event.getY(index)-lastPoint.y);</span><br><span class="line">                    lastPoint.set(event.getX(index), event.getY(index));</span><br><span class="line">                    mBitmapRectF = <span class="keyword">new</span> RectF(<span class="number">0</span>,<span class="number">0</span>,mBitmap.getWidth(), mBitmap.getHeight());</span><br><span class="line">                    mBitmapMatrix.mapRect(mBitmapRectF);</span><br><span class="line">                    invalidate();</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Paint mDeafultPaint;</span><br><span class="line">    <span class="keyword">boolean</span> isFirstDraw = <span class="keyword">true</span>;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onDraw</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (isFirstDraw)&#123;<span class="comment">//初始位置居中</span></span><br><span class="line">            isFirstDraw = <span class="keyword">false</span>;</span><br><span class="line">            mBitmapMatrix.setScale(<span class="number">1.0f</span>,<span class="number">1.0f</span> , mBitmapWidth /<span class="number">2</span> , mBitmapHeight /<span class="number">2</span>);</span><br><span class="line">            mBitmapMatrix.setTranslate(mWidth/<span class="number">2</span> - mBitmapWidth /<span class="number">2</span>,mHeight/<span class="number">2</span> - mBitmapHeight /<span class="number">2</span>);</span><br><span class="line">            mBitmapRectF = <span class="keyword">new</span> RectF(<span class="number">0</span>,<span class="number">0</span>,mBitmap.getWidth(), mBitmap.getHeight());</span><br><span class="line">            mBitmapMatrix.mapRect(mBitmapRectF);</span><br><span class="line">        &#125;</span><br><span class="line">        canvas.drawBitmap(mBitmap, mBitmapMatrix, mDeafultPaint);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">float</span> mScale = <span class="number">1.0f</span>;</span><br><span class="line">    <span class="keyword">float</span> mMaxScale = mScale * <span class="number">8.0f</span>;</span><br><span class="line">    <span class="keyword">float</span> mMinScale = mScale * <span class="number">0.5f</span>;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onScale</span><span class="params">(ScaleGestureDetector detector)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (mBitmap == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 缩放因子</span></span><br><span class="line">        <span class="keyword">float</span> scaleFactor = detector.getScaleFactor();</span><br><span class="line">        <span class="comment">// 已经缩放值</span></span><br><span class="line">        <span class="keyword">float</span> scale = getmScale();</span><br><span class="line">        <span class="keyword">float</span> scaleResult = scale * scaleFactor;</span><br><span class="line">        <span class="keyword">if</span> (scaleResult &gt;= mMaxScale &amp;&amp; scaleFactor &gt; <span class="number">1.0f</span>)</span><br><span class="line">            scaleFactor = mMaxScale / scale;</span><br><span class="line">        <span class="keyword">if</span> (scaleResult &lt;= mMinScale &amp;&amp; scaleFactor &lt; <span class="number">1.0f</span>)</span><br><span class="line">            scaleFactor = mMinScale / scale;</span><br><span class="line">        mBitmapMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());</span><br><span class="line">        setImageMatrix(mBitmapMatrix);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onScaleBegin</span><span class="params">(ScaleGestureDetector scaleGestureDetector)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onScaleEnd</span><span class="params">(ScaleGestureDetector scaleGestureDetector)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">float</span> scale = getmScale();</span><br><span class="line">        <span class="keyword">if</span> (scale &lt; mScale) &#123;</span><br><span class="line">            mBitmapMatrix.postScale(mScale / scale, mScale / scale, mWidth / <span class="number">2</span>, mHeight / <span class="number">2</span>);</span><br><span class="line">            setImageMatrix(mBitmapMatrix);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 当前缩放的值</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">float</span> <span class="title">getmScale</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">float</span>[] floats = <span class="keyword">new</span> <span class="keyword">float</span>[<span class="number">9</span>];</span><br><span class="line">        mBitmapMatrix.getValues(floats);</span><br><span class="line">        <span class="keyword">return</span> floats[Matrix.MSCALE_X];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">OperateListener</span> </span>&#123;</span><br><span class="line">        <span class="function"><span class="keyword">void</span> <span class="title">onClicked</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="function"><span class="keyword">void</span> <span class="title">onDoubleClicked</span><span class="params">()</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    OperateListener operateListener;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setOperateListener</span><span class="params">(OperateListener operateListener)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.operateListener = operateListener;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onSingleTapConfirmed</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;<span class="comment">//单击事件回调</span></span><br><span class="line">        <span class="keyword">if</span> (operateListener != <span class="keyword">null</span>)&#123;</span><br><span class="line">            operateListener.onClicked();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onDoubleTap</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onDoubleTapEvent</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;<span class="comment">//双击事件回调，回调2次</span></span><br><span class="line">        <span class="keyword">if</span> (operateListener != <span class="keyword">null</span>)&#123;</span><br><span class="line">            operateListener.onDoubleClicked();</span><br><span class="line">        &#125;</span><br><span class="line">        isFirstDraw =<span class="keyword">true</span>;</span><br><span class="line">        invalidate();</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onDown</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;<span class="comment">//按下那一刻</span></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onShowPress</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onSingleTapUp</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onScroll</span><span class="params">(MotionEvent motionEvent, MotionEvent motionEvent1, <span class="keyword">float</span> v, <span class="keyword">float</span> v1)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onLongPress</span><span class="params">(MotionEvent motionEvent)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onFling</span><span class="params">(MotionEvent motionEvent, MotionEvent motionEvent1, <span class="keyword">float</span> v, <span class="keyword">float</span> v1)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre>

  </div>
  <div>
  
  <div class="post-note note-warning copyright" style="margin-top: 42px">
    <p><span style="font-weight: bold;">作者：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/about">Cupster</a></p>
    <p><span style="font-weight: bold;">文章链接：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/2019/07/27/016-Android%E8%87%AA%E5%AE%9A%E4%B9%89View(11)%EF%BC%9A%E6%89%8B%E5%8A%BF%E7%9B%91%E5%90%AC%E5%A4%84%E7%90%86%E5%AE%9E%E8%B7%B5%E4%B9%8B%E5%8F%8C%E6%8C%87%E7%BC%A9%E6%94%BE%E5%8F%8C%E5%87%BB%E5%A4%8D%E5%8E%9FImageView/">http://example.com/2019/07/27/016-Android%E8%87%AA%E5%AE%9A%E4%B9%89View(11)%EF%BC%9A%E6%89%8B%E5%8A%BF%E7%9B%91%E5%90%AC%E5%A4%84%E7%90%86%E5%AE%9E%E8%B7%B5%E4%B9%8B%E5%8F%8C%E6%8C%87%E7%BC%A9%E6%94%BE%E5%8F%8C%E5%87%BB%E5%A4%8D%E5%8E%9FImageView/</a></p>
    <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
  </div>
  
  </div>
</article>
<div class="nav">
  
  <div class="nav-item-prev">
    <a href="/2019/08/02/017-Android自定义View(12)：手势绘制及GestureOverlayView事件浅析/" class="nav-link">
      <i class="iconfont icon-left nav-prev-icon"></i>
      <div>
        <div class="nav-label">上一篇</div>
        
        <div class="nav-title">017-Android自定义View(12)：手势绘制及GestureOverlayView事件浅析 </div>
        
      </div>
    </a>
  </div>
  
  
  <div class="nav-item-next">
    <a href="/2019/07/23/015-Android自定义View(10)：手势监听&amp;处理/" class="nav-link">
      <div>
        <div class="nav-label">下一篇</div>
        
        <div class="nav-title">015-Android自定义View(10)：手势监听&amp;处理 </div>
        
      </div>
      <i class="iconfont icon-right nav-next-icon"></i>
    </a>
  </div>
  
</div>

<div class="card card-content toc-card" id="mobiletoc">
  <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E6%95%88%E6%9E%9C"><span class="toc-text">1.效果</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E7%9B%91%E5%90%AC%E6%89%8B%E5%8A%BF%E5%AE%9E%E7%8E%B0%E5%8A%9F%E8%83%BD"><span class="toc-text">2.监听手势实现功能</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E7%94%A8%E6%B3%95%E5%8F%8A%E4%BB%A3%E7%A0%81%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.用法及代码详解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1%E5%B1%9E%E6%80%A7%E6%B7%BB%E5%8A%A0"><span class="toc-text">3.1属性添加</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2xml%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8"><span class="toc-text">3.2xml布局文件中使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3Activity%E4%BD%BF%E7%94%A8"><span class="toc-text">3.3Activity使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4ScaleImageView%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.4ScaleImageView详解</span></a></li></ol></li></ol>
</div></main>
          <aside class="left-column">
            
            <div class="card card-author">
              
<img src="/img/ic_head.jpg" class="author-img">

<p class="author-name">Cupster</p>
<p class="author-description">深山磨柴斧，一鸣震江湖</p>
<div class="author-message">
  <a class="author-posts-count" href="/archives">
    <span>66</span>
    <span>文章</span>
  </a>
  <a class="author-categories-count" href="/categories">
    <span>5</span>
    <span>分类</span>
  </a>
  <a class="author-tags-count" href="/tags">
    <span>31</span>
    <span>标签</span>
  </a>
</div>

<div class="author-card-society">
  
    <div class="author-card-society-icon">
      <a target="_blank" rel="noopener" href="https://cupster.blog.csdn.net/">
        <i class="iconfont /img/ic_csdn.png society-icon"></i>
      </a>
    </div>
  
</div>

            </div>
            
            <div class="sticky-tablet">
  
  
  <article class="display-when-two-columns spacer">
    <div class="card card-content toc-card">
      <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E6%95%88%E6%9E%9C"><span class="toc-text">1.效果</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E7%9B%91%E5%90%AC%E6%89%8B%E5%8A%BF%E5%AE%9E%E7%8E%B0%E5%8A%9F%E8%83%BD"><span class="toc-text">2.监听手势实现功能</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E7%94%A8%E6%B3%95%E5%8F%8A%E4%BB%A3%E7%A0%81%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.用法及代码详解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1%E5%B1%9E%E6%80%A7%E6%B7%BB%E5%8A%A0"><span class="toc-text">3.1属性添加</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2xml%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8"><span class="toc-text">3.2xml布局文件中使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3Activity%E4%BD%BF%E7%94%A8"><span class="toc-text">3.3Activity使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4ScaleImageView%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.4ScaleImageView详解</span></a></li></ol></li></ol>
    </div>
  </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header"><i class="iconfont icon-fenlei" style="padding-right: 2px;"></i>分类</div>
  <div class="categories-list">
    
      <a href="/categories/Android/">
        <div class="categories-list-item">
          Android
          <span class="categories-list-item-badge">38</span>
        </div>
      </a>
    
      <a href="/categories/Linux/">
        <div class="categories-list-item">
          Linux
          <span class="categories-list-item-badge">6</span>
        </div>
      </a>
    
      <a href="/categories/Dev-Base/">
        <div class="categories-list-item">
          Dev-Base
          <span class="categories-list-item-badge">12</span>
        </div>
      </a>
    
      <a href="/categories/Kotlin/">
        <div class="categories-list-item">
          Kotlin
          <span class="categories-list-item-badge">9</span>
        </div>
      </a>
    
      <a href="/categories/自动化脚本/">
        <div class="categories-list-item">
          自动化脚本
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header"><i class="iconfont icon-biaoqian" style="padding-right: 2px;"></i>热门标签</div>
  <div class="tags-list">
    
    <a href="/tags/Android/" title="Android"><div class="tags-list-item">Android</div></a>
    
    <a href="/tags/Android自定义View/" title="Android自定义View"><div class="tags-list-item">Android自定义View</div></a>
    
    <a href="/tags/MacOS/" title="MacOS"><div class="tags-list-item">MacOS</div></a>
    
    <a href="/tags/Kotlin/" title="Kotlin"><div class="tags-list-item">Kotlin</div></a>
    
    <a href="/tags/Android持久化/" title="Android持久化"><div class="tags-list-item">Android持久化</div></a>
    
    <a href="/tags/CentOS/" title="CentOS"><div class="tags-list-item">CentOS</div></a>
    
    <a href="/tags/Linux/" title="Linux"><div class="tags-list-item">Linux</div></a>
    
    <a href="/tags/Android事件/" title="Android事件"><div class="tags-list-item">Android事件</div></a>
    
    <a href="/tags/Android基础/" title="Android基础"><div class="tags-list-item">Android基础</div></a>
    
    <a href="/tags/Android手势/" title="Android手势"><div class="tags-list-item">Android手势</div></a>
    
    <a href="/tags/Scrcpy/" title="Scrcpy"><div class="tags-list-item">Scrcpy</div></a>
    
    <a href="/tags/Android动画/" title="Android动画"><div class="tags-list-item">Android动画</div></a>
    
    <a href="/tags/Git/" title="Git"><div class="tags-list-item">Git</div></a>
    
    <a href="/tags/Java/" title="Java"><div class="tags-list-item">Java</div></a>
    
    <a href="/tags/Docker/" title="Docker"><div class="tags-list-item">Docker</div></a>
    
    <a href="/tags/Android-Dialog/" title="Android Dialog"><div class="tags-list-item">Android Dialog</div></a>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
          <aside class="right-column">
            <div class="sticky-widescreen">
  
  
  <article class="card card-content toc-card">
    <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E6%95%88%E6%9E%9C"><span class="toc-text">1.效果</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E7%9B%91%E5%90%AC%E6%89%8B%E5%8A%BF%E5%AE%9E%E7%8E%B0%E5%8A%9F%E8%83%BD"><span class="toc-text">2.监听手势实现功能</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E7%94%A8%E6%B3%95%E5%8F%8A%E4%BB%A3%E7%A0%81%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.用法及代码详解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1%E5%B1%9E%E6%80%A7%E6%B7%BB%E5%8A%A0"><span class="toc-text">3.1属性添加</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2xml%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8"><span class="toc-text">3.2xml布局文件中使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3Activity%E4%BD%BF%E7%94%A8"><span class="toc-text">3.3Activity使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4ScaleImageView%E8%AF%A6%E8%A7%A3"><span class="toc-text">3.4ScaleImageView详解</span></a></li></ol></li></ol>
  </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header"><i class="iconfont icon-wenzhang_huaban" style="padding-right: 2px;"></i>最近文章</div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-03-02</div>
        <a href="/2021/03/02/Git commit规范/"><div class="recent-posts-item-content">Git commit规范</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-02-16</div>
        <a href="/2021/02/16/AutoJS一文精通AutoJS脚本教程详解/"><div class="recent-posts-item-content">AutoJS一文精通AutoJS脚本教程详解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-21</div>
        <a href="/2021/01/21/架构师进阶：注解Annotation全解/"><div class="recent-posts-item-content">架构师进阶：注解Annotation全解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-06</div>
        <a href="/2021/01/06/ConstraintLayout详解/"><div class="recent-posts-item-content">ConstraintLayout详解</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
        </div>
      </div>
    </div>
  </div>
  
  <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>Copyright ©
          
          2020 -
          
          2021
        </span>
        &nbsp;
        <a href="/" class="footer-link">不负明天 </a>
      </div>
    </div>

    
    <div class="footer-dsc">
      
      Powered by
      <a href="https://hexo.io/" class="footer-link" target="_blank" rel="nofollow noopener noreferrer">&nbsp;Hexo </a>
      
      
      <span>&nbsp;|&nbsp;</span>
      
      
      Theme -
      <a href="https://github.com/theme-kaze" class="footer-link" target="_blank"
        rel="nofollow noopener noreferrer">&nbsp;Kaze</a>
      
    </div>
    
    
    
    
      <div class="footer-dsc">
        
        本站总访问量686<span id="busuanzi_value_site_pv"></span>次
        
        
        <span>&nbsp;|&nbsp;</span>
        
        
        本站总访客数219<span id="busuanzi_value_site_uv"></span>次
        
      </div>
      
    
</footer>
  <a role="button" id="scrollbutton" class="basebutton"  aria-label="回到顶部">
  <i class="iconfont icon-arrowleft button-icon"></i>
</a>
<a role="button" id="menubutton" class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a role="button" id="popbutton" class="basebutton" aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a role="button" id="darkbutton" class="basebutton darkwidget" aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a role="button" id="searchbutton" class="basebutton searchwidget" aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a>

  
  
  
  <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img');
    var i;
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a');
      wrapper.setAttribute('href', img[i].getAttribute('data-src'));
      wrapper.setAttribute('aria-label', 'illustration');
      wrapper.style.cssText = 'width: 100%; display: flex; justify-content: center;';
      if (img[i].alt) wrapper.dataset.caption = img[i].alt;
      wrapper.dataset.nolink = true;
      img[i].before(wrapper);
      wrapper.append(img[i]);
      var divWrap = document.createElement('div');
      divWrap.classList.add('gallery');
      wrapper.before(divWrap);
      divWrap.append(wrapper);
    }
    baguetteBox.run('.gallery');
  }
</script>
<script>loadScript("/js/lib/lightbox/baguetteBox.min.js", addImgLayout)</script>
  
  
  
<script src="/js/main.js"></script>

  
  <script>loadScript("/js/lib/busuanzi.min.js")</script>
  
  
  <script>
    var addLazyload = function () {
      var observer = lozad('.lozad', {
        load: function (el) {
          el.srcset = el.getAttribute('data-src');
        },
        loaded: function (el) {
          el.classList.add('loaded');
        }
      });
      observer.observe();
    }
  </script>
  <script>loadScript("/js/lib/lozad.min.js", addLazyload)</script>
  
  
</body>

</html>